package com.lims.admin.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import org.hibernate.validator.constraints.*;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javacommon.base.*;

/**
 * 
 * @author zzh
 *
 */
@Entity
@Table(name = "T_ROLE")
public class Role extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//date formats
	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * ID       db_column: OBJID 
     */ 	
	@Length(max=32)
	private java.lang.String objid;
    /**
     * 角色名称       db_column: ROLENAME 
     */ 	
	@Length(max=150)
	private java.lang.String rolename;
    /**
     * 其他描述       db_column: DESCRIBE 
     */ 	
	@Length(max=200)
	private java.lang.String describe;
	
	/**
	 * 角色编号
	 */
	private String roleno;
	//columns END
	

	public Role(){
	}

	public Role(
		java.lang.String objid
	){
		this.objid = objid;
	}

	

	public void setObjid(java.lang.String value) {
		this.objid = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "uuid")
	@Column(name = "OBJID", nullable = false, insertable = true, updatable = true, length = 32)
	public java.lang.String getObjid() {
		return this.objid;
	}
	
	@Column(name = "ROLENAME", unique = false, nullable = true, insertable = true, updatable = true, length = 150)
	public java.lang.String getRolename() {
		return this.rolename;
	}
	
	public void setRolename(java.lang.String value) {
		this.rolename = value;
	}
	
	@Column(name = "DESCRIBE", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getDescribe() {
		return this.describe;
	}
	
	public void setDescribe(java.lang.String value) {
		this.describe = value;
	}
	
	@Column(name = "roleno", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
	public String getRoleno() {
		return roleno;
	}

	public void setRoleno(String roleno) {
		this.roleno = roleno;
	}
	
	private List<Menu> menus = new ArrayList<Menu>(0);
	
	@ManyToMany
	@JoinTable(name="t_role_menu_mapping",
			joinColumns={@JoinColumn(name="rid")},
			inverseJoinColumns={@JoinColumn(name="mid")})
	public List<Menu> getMenus() {
		return menus;
	}

	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Objid",getObjid())
			.append("Rolename",getRolename())
			.append("Describe",getDescribe())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getObjid())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Role == false) return false;
		if(this == obj) return true;
		Role other = (Role)obj;
		return new EqualsBuilder()
			.append(getObjid(),other.getObjid())
			.isEquals();
	}
}

